#ifndef PURG_THREAD_SAFETY_H
#define PURG_THREAD_SAFETY_H

#include <pthread.h>

#include "buffer.h"

#ifndef PURG_C_INTERFACE_COMPILE
namespace  purg
{
#endif

  template <typename STREAM>
  class thread_safety_stream
  {
    public:

      class  ts_state : public STREAM::state
      {
        public:
          pthread_mutex_t   mutex;

          ts_state ();
          ~ts_state ();
      };

      typedef typename STREAM::seed    seed;
      typedef          ts_state        state;
      enum { buffer_length = STREAM::buffer_length };

      static void  initialize ( state & , buffer & , seed & , size_t );
      static void  update_buffer ( state & , buffer & );

      static void  lock ( state & );
      static void  unlock ( state & );
  };

#ifndef PURG_C_INTERFACE_COMPILE
}
#endif

#include "thread_safety.tmpl.h"
#endif
